Maps

Martin John Hadley

2016-12-30

Geolines Map

Our sample dataset is included in the library, data_geo_lines_map and comprises a set of send-receive coordinates. The geo_lines_map function requires a dataset with at least the following columns:

library(oidnChaRts)
head(data_geo_lines_map)
## # A tibble: 6 × 9
##   sender.location sender.latitude sender.longitude  receiver.location
##             <chr>           <dbl>            <dbl>              <chr>
## 1  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 2  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 3  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 4  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 5  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 6  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## # ... with 5 more variables: receiver.latitude <dbl>,
## #   receiver.longitude <dbl>, date <date>, journey <chr>,
## #   number.of.letters <int>

Hat tip to http://personal.tcu.edu/kylewalker/interactive-flow-visualization-in-r.html for the geospheres library which computes great circles.

Leaflet

Basic Example

The minimal number of arguments required for geo_line_map are as follows:

library(leaflet)
geo_lines_map(data_geo_lines_map, 
              library = "leaflet")
## NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

There are additional arguments that may control the line.options and termini.options (the dots at each end of the geo_line)

geo_lines_map(data_geo_lines_map, 
              library = "leaflet",
              line.options = list(weight = 3))
## NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

The leaflet map produced by geo_lines_map can be used in pipe chains like any other leaflet map:

geo_lines_map(data_geo_lines_map, 
              library = "leaflet",
              line.options = list(weight = 3)) %>%
  addProviderTiles("Stamen.Watercolor")
## NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

Tooltips

The geo_lines_map function has been designed for tooltips to be easily added to the lines of termini, in the example below a popup will show when a geo_line is clicked.

label_journey <- function(sender.location = NA, receiver.location = NA){
  paste0(
    "<p>Sender: ", sender.location,
    "</p>",
    "<p>Receiver: ", receiver.location
  )
}
geo_lines_map(data_geo_lines_map, 
              library = "leaflet",
              line.popup = ~label_journey(sender.location, receiver.location),
              line.options = list(weight = 3)) %>%
  addProviderTiles("Stamen.Watercolor")
## NOTE: rgdal::checkCRSArgs: no proj_defs.dat in PROJ.4 shared files

Choropleth from points

Our sample dataset is included in the library, data_geo_points and comprises a set of coordinates . The geo_lines_map function requires a dataset with at least the following columns:

library(oidnChaRts)
head(data_geo_lines_map)
## # A tibble: 6 × 9
##   sender.location sender.latitude sender.longitude  receiver.location
##             <chr>           <dbl>            <dbl>              <chr>
## 1  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 2  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 3  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 4  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 5  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## 6  DEU, Mockethal        50.97178         13.96013 USA, New York (NY)
## # ... with 5 more variables: receiver.latitude <dbl>,
## #   receiver.longitude <dbl>, date <date>, journey <chr>,
## #   number.of.letters <int>